package com.netease.rtcdemo;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.preference.EditTextPreference;
import android.util.AttributeSet;

public class NeutralEditTextPreference extends EditTextPreference {
    private DialogInterface.OnClickListener mOnNeturalButtonClickListener;
    public NeutralEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public NeutralEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public NeutralEditTextPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NeutralEditTextPreference(Context context) {
        super(context);
    }
    public void setOnNeutralButtonClickListener(DialogInterface.OnClickListener listener) {
        mOnNeturalButtonClickListener = listener;
    }
    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
        super.onPrepareDialogBuilder(builder);
        builder.setNeutralButton("扫码", (dialog, which) -> {
            switch (which) {
                case DialogInterface.BUTTON_NEUTRAL:
                    if (mOnNeturalButtonClickListener != null) {
                        mOnNeturalButtonClickListener.onClick(dialog, which);
                    }
                    break;
                default:
                    break;
            }
        });
    }
}
